package com.five.wisdomClass.controller;

import com.five.wisdomClass.bean.ResponseData;
import com.five.wisdomClass.entity.*;
import com.five.wisdomClass.service.IStudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


@Tag(name="学生的基本操作")
@Slf4j
@RestController
@CrossOrigin
@RequiredArgsConstructor
@RequestMapping("/student")
public class StudentController extends BaseController{

    private final IStudentService studentService;

    @Operation(summary = "查看自己的同班同学")
    @PostMapping("/getclassmates")
    public ResponseData<Object> getClassMates(@RequestBody Student student){
        return returnObject(studentService.getSpecializedClassMember(student));
    }

    @Operation(summary = "查看自己的个人信息")
    @PostMapping("/getselfinfo")
    public ResponseData<Object> getSelfInfo(@RequestBody Student student){
        return returnObject(studentService.getSelfInfo(student));
    }

    @Operation(summary = "获取课程信息")
    @PostMapping("/getcourses")
    public ResponseData<Object> getCourses(@RequestBody Student student){
        // 构造课程集合将公共课程和选修课程一起返回
        List<Course> courseList = new ArrayList<>();
        List<Course> publicCourse = studentService.getPublicCourses(student);
        List<Course> takeCourse = studentService.getTakeCourses(student);
        courseList.addAll(publicCourse);
        courseList.addAll(takeCourse);
        return returnObject(courseList);
    }

    @Operation(summary = "获取课程成绩信息")
    @PostMapping("/getselfscores")
    public ResponseData<Object> getScores(@RequestBody Student student){
        return returnObject(studentService.getSelfScores(student));
    }

    @Operation(summary = "添加个人计划")
    @PostMapping("/addplan")
    public ResponseData<Boolean> addPlan(@RequestBody SelfPlan selfPlan){
        return returnBoolean(studentService.addPlan(selfPlan));
    }

    @Operation(summary = "删除个人计划")
    @DeleteMapping("/deleteplan/{id}")
    public ResponseData<Boolean> deletePlan(@PathVariable("id") Integer id){
        return returnBoolean(studentService.deletePlan(id));
    }

    @Operation(summary = "修改个人计划")
    @PutMapping("/editplan")
    public ResponseData<Boolean> deletePlan(String context,Integer id){
        return returnBoolean(studentService.editPlan(context,id));
    }

    @Operation(summary = "查看个人计划")
    @PostMapping("/getplans")
    public ResponseData<Object> getPlans(@RequestBody Student student){
        return returnObject(studentService.getPlans(student));
    }

    @Operation(summary = "提交请假申请")
    @PostMapping("/submitleave")
    public ResponseData<Object> submitLeave(@RequestBody Leave leave){
        return returnObject(studentService.submitLeave(leave));
    }
}
